#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/laser_scan.hpp>

class LidarSubscriber : public rclcpp::Node {
public:
    LidarSubscriber() : Node("lidar_subscriber") {
        subscription_ = this->create_subscription<sensor_msgs::msg::LaserScan>(
            "/scan", 10, std::bind(&LidarSubscriber::lidar_callback, this, std::placeholders::_1));
    }

private:
    void lidar_callback(const sensor_msgs::msg::LaserScan::SharedPtr msg) {
        int num_ranges = msg->ranges.size();
        int mid = num_ranges / 2;
        float mid_range = msg->ranges[mid];
        RCLCPP_INFO(this->get_logger(), "Mid-range value: %f", mid_range);
        
    }

    rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr subscription_;
};

int main(int argc, char * argv[]) {
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<LidarSubscriber>());
    rclcpp::shutdown();
    return 0;
}